import request from '../util/request'

// 个人资料
export const getProfile = params =>
  request({
    url: 'v1_0/user/profile',
    needToken: true,
    params: params
  })

export const followUser = target =>
  request({
    url: 'v1_0/user/followings',
    method: 'POST',
    needToken: true,
    data: {
      target
    }
  })
// 取消关注用户
export const cancelFollowUser = target =>
  request({
    url: `v1_0/user/followings/${target}`,
    method: 'DELETE',
    needToken: true
  })
// 用户个人信息
export const getInfo = () => {
  return request({
    url: 'v1_0/user',
    method: 'GET',
    needToken: true
  })
}
// 编辑页面信息
export function edtiInfo (data) {
  return request({
    url: 'v1_0/user/profile',
    method: 'PATCH',
    needToken: true,
    data: data
  })
}

// 上传头像
export function edtifile (fd) {
  return request({
    url: 'v1_0/user/photo',
    method: 'PATCH',
    needToken: true,
    data: fd
  })
}

export const block = target => {
  return request({
    url: '/v1_0/user/blacklists',
    data: {
      target
    },
    method: 'POST',
    needToken: true
  })
}
// 获得用户阅读历史接口
export function getHistoriesList (params) {
  return request({
    url: 'v1_0/user/histories',
    method: 'GET',
    needToken: true,
    params: params
  })
}

// 获得用户收藏列表
export function getCollections (params) {
  return request({
    url: 'v1_0/article/collections',
    method: 'GET',
    needToken: true,
    params: params
  })
}
// 获取用户作品
export function getArticles (params) {
  return request({
    url: 'v1_0/user/articles',
    method: 'GET',
    needToken: true,
    params: params
  })
}

// 获得系统公告列表
export function getAnnouncements (params) {
  return request({
    url: '/v1_0/announcements',
    method: 'GET',
    params: params
  })
}

// 获得用户统计数据
export function getFigure (target) {
  return request({
    url: '/v1_0/user/figure',
    method: 'GET',
    needToken: true,
    params: {
      target: target
    }
  })
}

// 时间格式化
export const newDate = dateTime => {
  const date = new Date(dateTime) // 转换成Data();
  console.log('返回的标准未格式化时间：', date)
  var y = date.getFullYear()
  console.log('年：', y)
  var m = date.getMonth() + 1
  m = m < 10 ? '0' + m : m
  var d = date.getDate()
  d = d < 10 ? '0' + d : d
  return y + '-' + m + '-' + d
}
